//
//  UIBarButtonItem+Extension.swift
//  weibo
//
//  Created by Fly on 2017/12/15.
//  Copyright © 2017年 Fly. All rights reserved.
//

import Foundation
import UIKit

extension UIBarButtonItem {
    
    // 创建 自定义的UIBarButtonItem
    // MARK: 便利构造函数
    /// - Parameters: 创建 UIBarButtonItem
    ///   - title: 按钮文本
    ///   - fontSize: 文本字号，默认16.0号
    ///   - titleColor: 文本normal颜色，默认黑色
    ///   - highlightedColor: 文本highlight颜色，默认橙色
    ///   - target: 监听对象
    ///   - action: 触发方法
    convenience init(title: String, fontSize: CGFloat = 16.0, titleNormalColor: UIColor = UIColor.gray, titleHighlightedColor: UIColor = UIColor.black, isBackBtn: Bool = false, target: AnyObject?, action: Selector) {
        
//        let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 30))
        let btn = UIButton()
        
        btn.setTitle(title, for: .normal)
        
        btn.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        
        btn.setTitleColor(titleNormalColor, for: .normal)
        
        btn.setTitleColor(titleHighlightedColor, for: .highlighted)
        
        if isBackBtn == true {
            
            btn.setImage(#imageLiteral(resourceName: "back"), for: .normal)
            
            btn.setImage(#imageLiteral(resourceName: "back_heightlight"), for: .highlighted)
            
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        btn.sizeToFit()
        
        self.init(customView:btn)
        
    }

}
